package com.bosicloud.cmb.ibp.api.manager.util;

import com.bosicloud.cmb.ibp.api.manager.commom.model.IbpApiDocParams;
import com.bosicloud.cmb.ibp.api.manager.commom.vo.ResponseMessagesVO;
import io.swagger.models.Operation;
import io.swagger.models.Swagger;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Slf4j
public class OperationProcessor {


    private final Swagger swagger;
    private final ParameterProcessor parameterProcessor;
    private final ResponseProcessor responseProcessor;

    public OperationProcessor(Swagger swagger) {
        this.swagger = swagger;
        this.parameterProcessor = new ParameterProcessor(swagger);
        this.responseProcessor = new ResponseProcessor(swagger);
    }

    public List<IbpApiDocParams> processor(Operation operation) {
        if (Objects.isNull(operation)) {
            return Collections.emptyList();
        }
        return parameterProcessor.processParameters(operation.getParameters());
    }

    public List<ResponseMessagesVO> processorResponseMessages(Operation operation) {
        if (Objects.isNull(operation)) {
            return Collections.emptyList();
        }
        return responseProcessor.processor(operation.getResponses());
    }
}
